﻿using AmiDraw.Lib.Models;
using PropertyChanged;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AmiDraw.Editor.Component
{
    /// <summary>
    /// MultiplotElement.xaml 的交互逻辑
    /// </summary>
    [AddINotifyPropertyChangedInterface]
    public partial class MultiplotElement : UserControl
    {

        public object InnerContent
        {
            get { return GetValue(InnerContentProperty); }
            set { SetValue(InnerContentProperty, value); }
        }

        public static readonly DependencyProperty InnerContentProperty =
            DependencyProperty.Register("InnerContent", typeof(object), typeof(MultiplotElement), new PropertyMetadata(null));

        private bool isMove = false;
        private Point oldPoint;

        public MultiplotElement()
        {
            InitializeComponent();
        }

        private void Button_MouseDown(object sender, MouseButtonEventArgs e)
        {

            isMove = true;
            oldPoint = e.GetPosition(null);
            Debug.WriteLine($"按下");

        }

        private void Button_MouseUp(object sender, MouseButtonEventArgs e)
        {
            isMove = false;
            Debug.WriteLine($"松开");

        }

        private void Button_MouseMove(object sender, MouseEventArgs e)
        {
            if (isMove)
            {

                FrameworkElement currEle = this as FrameworkElement;

                var changedX = e.GetPosition(null).X - oldPoint.X;
                var changedY = e.GetPosition(null).Y - oldPoint.Y;
                (this.DataContext as MultiplotElemtentBase).X += Convert.ToInt32(changedX);
                (this.DataContext as MultiplotElemtentBase).Y += Convert.ToInt32(changedY);
                oldPoint = e.GetPosition(null);

            }

        }

        private void SizeButton_MouseUp(object sender, MouseButtonEventArgs e)
        {
            isMove = false;
            Debug.WriteLine($"松开");
        }

        private void SizeButton_MouseMove(object sender, MouseEventArgs e)
        {
            if (isMove)
            {

                FrameworkElement currEle = this as FrameworkElement;

                var changedX = e.GetPosition(null).X - oldPoint.X;
                var changedY = e.GetPosition(null).Y - oldPoint.Y;
                (this.DataContext as MultiplotElemtentBase).Width += Convert.ToInt32(changedX);
                (this.DataContext as MultiplotElemtentBase).Height += Convert.ToInt32(changedY);
                oldPoint = e.GetPosition(null);

            }
        }

        private void SizeButton_MouseDown(object sender, MouseButtonEventArgs e)
        {
            isMove = true;
            oldPoint = e.GetPosition(null);
            Debug.WriteLine($"按下");

        }
    }

}
